//
//  DoctoreIDViewController.m
//  quickDoctor
//
//  Created by sdos on 2017/3/11.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "DoctoreIDViewController.h"
#import <Masonry.h>
#import "focusDoctorMolde.h"
#import "KYCatogryView.h"
#import "JZTJCollectionViewCell.h"
#import "YSJJCollectionViewCell.h"


#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

// 宏定义 随机颜色
#define RandomColor RGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))



@interface DoctoreIDViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,KYCatogryViewDelegate>

@property(nonatomic,weak)UIView *headView;
@property(nonatomic,weak)UIView *footView;
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,weak)KYCatogryView *catogryView;
@property(nonatomic,strong)UIButton *rightButton;

@end

@implementation DoctoreIDViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}

- (void)setupUI
{
    self.title = @"医生基本信息";
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    _rightButton = rightButton;
    [rightButton setImage:[UIImage imageNamed:@"kongxin"] forState: UIControlStateNormal];
    [rightButton setImage:[UIImage imageNamed:@"shixin"] forState: UIControlStateSelected];
    [rightButton addTarget:self action:@selector(clickRightButton) forControlEvents:UIControlEventTouchUpInside];
    [rightView addSubview:rightButton];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightView];

    self.view.backgroundColor = [UIColor lightGrayColor];
    [self setupHeadView];
    [self setCenterView];
    [self setFootView];
}

- (void)clickRightButton
{
    _rightButton.selected = !(_rightButton.selected);
}
#pragma mark
#pragma mark -顶部视图
- (void)setupHeadView
{
    self.navigationController.navigationBar.translucent = NO;
    //添加顶部视图
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    _headView = headView;
    headView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:headView];
    
    //添加控件
    //添加头像
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:@"illness_img_person.png"];
    [headView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.offset(10);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    //姓名
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.font = [UIFont systemFontOfSize:18];
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.text = _model.doctorName;
    [headView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView);
        make.leading.equalTo(iconView.mas_trailing).offset(10);
    }];
    //职位
    UILabel *jobLabel = [[UILabel alloc] init];
    jobLabel.font = [UIFont systemFontOfSize:16];
    jobLabel.textColor = [UIColor lightGrayColor];
    jobLabel.text = _model.doctorJob;
    [headView addSubview:jobLabel];
    [jobLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel);
        make.leading.equalTo(nameLabel.mas_trailing).offset(10);
    }];
    //所属医院
    UILabel *hospitalLabel = [[UILabel alloc] init];
    hospitalLabel.font = [UIFont systemFontOfSize:18];
    hospitalLabel.textColor = [UIColor lightGrayColor];
    hospitalLabel.text = _model.doctorHospital;
    [headView addSubview:hospitalLabel];
    [hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(nameLabel);
        make.bottom.equalTo(iconView.mas_bottom).offset(-5);
    }];
    //添加预约图片
    UIImageView *cureView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yuyueliang"]];
    [headView addSubview:cureView];
    [cureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(50);
        make.top.equalTo(iconView.mas_bottom).offset(20);
    }];
    //添加预约数
    UILabel *cureLabel = [[UILabel alloc] init];
    cureLabel.font = [UIFont systemFontOfSize:14];
    cureLabel.textColor = RGBColor(47, 198, 197);
    cureLabel.text = _model.cureNumber;
    [headView addSubview:cureLabel];
    [cureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cureView);
        make.leading.equalTo(cureView.mas_trailing).offset(8);
    }];
    //添加鲜花图片
    UIImageView *flowerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xianhua"]];
    [headView addSubview:flowerView];
    //约束
    [flowerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cureLabel);
        make.leading.equalTo(cureLabel.mas_trailing).offset(80);
    }];
    //添加鲜花数
    UILabel *flowerNumberLable = [[UILabel alloc] init];
    flowerNumberLable.font = [UIFont systemFontOfSize:14];
    flowerNumberLable.textColor = RGBColor(47, 198, 197);
    flowerNumberLable.text = _model.flowerNumber;
    [headView addSubview:flowerNumberLable];
    //约束
    [flowerNumberLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(flowerView.mas_trailing).offset(8);
        make.centerY.equalTo(flowerView);
    }];
   
    //添加点赞数
    UILabel *praiseNumberLable = [[UILabel alloc] init];
    praiseNumberLable.textColor = RGBColor(47, 198, 197);
    praiseNumberLable.font = [UIFont systemFontOfSize:14];
    praiseNumberLable.text = _model.praiseNumber;
    [headView addSubview:praiseNumberLable];
    //约束
    [praiseNumberLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(flowerNumberLable);
        make.trailing.offset(-50);
    }];
    //添加点赞图片
    UIImageView *praiseView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jinqi"]];
    [headView addSubview:praiseView];
    //约束
    [praiseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(praiseNumberLable);
        make.trailing.equalTo(praiseNumberLable.mas_leading).offset(-8);
    }];
}

#pragma mark
#pragma mark -中间视图
- (void)setCenterView
{
    //添加分类视图
    KYCatogryView *catogryView = [[KYCatogryView alloc] init];
    catogryView.backgroundColor = [UIColor whiteColor];
    _catogryView = catogryView;
    //设置代理
    catogryView.delegate = self;
   
    [self.view addSubview:catogryView];
    [catogryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width,60));
        make.top.equalTo(_headView.mas_bottom).offset(5);
        make.centerX.offset(0);
    }];
    
    
    //添加collectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _collectionView = collectionView;
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.pagingEnabled = YES;
    collectionView.bounces = NO;
    //滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    
    [self.view addSubview:collectionView];
    //约束
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.top.equalTo(catogryView.mas_bottom).offset(0);
        make.height.equalTo(@318);
//        make.bottom.equalTo(_footView.mas_top).offset(0);
    }];
    
    [collectionView registerClass:[JZTJCollectionViewCell class] forCellWithReuseIdentifier:@"cell_ID"];
    [collectionView registerClass:[YSJJCollectionViewCell class] forCellWithReuseIdentifier:@"cell_ID_Other"];
}


#pragma mark
#pragma mark -collectionView数据源方法
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(self.view.width, 318);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
        JZTJCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell_ID" forIndexPath:indexPath];
        _collectionView.contentOffset = CGPointMake(0, 0);
        return cell;
    } else {
        
        YSJJCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell_ID_Other" forIndexPath:indexPath];
        
        return cell;
    }
}



#pragma mark
#pragma mark -通过代理实现联动
//点上 下面动
- (void)CatogryView:(KYCatogryView *)catogeryView Selection:(NSInteger)selection
{
        _collectionView.contentOffset = CGPointMake(self.view.width * selection, 0);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  
    CGFloat ratio = _collectionView.contentOffset.x/_collectionView.contentSize.width;
    
    _catogryView.ratio = ratio;
    
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    _catogryView.itemTag = _collectionView.contentOffset.x;
    
}




#pragma mark
#pragma mark -底部视图
- (void)setFootView
{
    UIView *footView = [[UIView alloc] init];
    _footView = footView;
    footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footView];
    [footView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.offset(0);
        make.height.mas_equalTo(70);
    }];
    
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:@"咨询医生" forState:UIControlStateNormal];
    button.backgroundColor = RGBColor(47, 198, 197);
    [footView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.offset(10);
        make.trailing.bottom.offset(-10);
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
